package com.chen.controller;


import com.chen.common.Result;
import com.chen.pojo.Book;
import com.chen.service.Impl.BookServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(value = "BookController", tags = "博客图书操作")
@RequestMapping("/book")
@SuppressWarnings("all")
public class BookController {

    @Resource
    private BookServiceImpl bookService;


    @PostMapping("/addBook")
    @ApiOperation("添加图书")
    public Result<?> addBook(@RequestBody Book book) {
        return bookService.addBook(book);
    }

    @PutMapping("/updateBook")
    @ApiOperation("更新图书")
    public Result<?> updateBook(@RequestBody Book book) {
        return bookService.updateBook(book);
    }


    @DeleteMapping("/deleteBook/{id}")
    @ApiOperation("删除图书")
    public Result<?> deleteBook(@PathVariable("id") Long id) {
        return bookService.deleteBook(id);
    }


    @GetMapping("/findById/{id}")
    public Result<?> findById(@PathVariable("id") Long id) {
        return bookService.selectById(id);
    }


    @GetMapping("/findAll")
    @ApiOperation("查询所有")
    public Result<?> findAll() {
        return bookService.selectAll();
    }


    @GetMapping("/findPages")
    @ApiOperation("分页")
    public Result<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search) {

        return bookService.findPage(pageNum,pageSize,search);

    }


}




